#ifndef __QUERY_RESULT
#define __QUERY_RESULT

#include "StdAfx.h"

namespace Database
{
	namespace _xxImpl_MySql
	{
		class QueryResult : public IQueryResult
		{
		private:
			MYSQL_ROW m_curRow;
			MYSQL_RES* m_pRes;
			MysqlRow m_row;
			bool m_working;

		public:
			QueryResult(MYSQL_RES* pRes)
			{
				m_curRow = mysql_fetch_row(pRes);
				m_working = m_curRow != 0;
				m_pRes = pRes;

				if(m_working)
				{
					m_row.Init(m_curRow, GetFieldCount());
				}
			}
			bool NextRow()
			{
				if(!m_working)
					return false;
				m_curRow = mysql_fetch_row(m_pRes);
				m_working = m_curRow != 0;
				if(m_working)
				{
					m_row.Init(m_curRow, GetFieldCount());
				}
				return m_working;
			}
			IDBRow& Fetch() { return m_row; }
			uint32 GetFieldCount() { return (uint32)mysql_num_fields(m_pRes); }
			uint32 GetRowCount() { return (uint32)mysql_num_rows(m_pRes);}

			~QueryResult()
			{
				if(m_working)
					m_row.Deinit();
				if(m_pRes)
					mysql_free_result(m_pRes);
			}
		};
	}
}



#endif /* __QUERY_RESULT */